#!/bin/sh
current_path=$(cd `dirname $0`; pwd)
rsync_path=`cd ../ && pwd`

rsync_version=`rpm -qa rsync`
## 1：安装rsync
if [  ${rsync_version}x == 'rsync-3.1.1-1.el7.rfx.x86_64'x ];
then
    echo "rsync has installed!"
else
    echo "rsync start installing!"
	rpm -ivh $rsync_path/rpm/rsync-3.1.1-1.el7.rfx.x86_64.rpm
fi

## 2：安装inotify
inotify_version=`rpm -qa inotify-tools`
if [  ${inotify_version}x == 'inotify-tools-3.14-9.el7.x86_64'x ];
then
    echo "inotify-tools has installed!"
else
    echo "inotify-tools start installing!"
	rpm -ivh $rsync_path/rpm/inotify-tools-3.14-9.el7.x86_64.rpm
	grep -q "fs.inotify.max_user_watches=1048576" /etc/sysctl.conf
	if [ $? -ne 0 ]; then
		echo "fs.inotify.max_queued_events=1048576"  >> /etc/sysctl.conf
		echo "fs.inotify.max_user_instances=1024"  >> /etc/sysctl.conf
		echo "fs.inotify.max_user_watches=1048576"  >> /etc/sysctl.conf
	fi
	/sbin/sysctl -p
fi

## 3：配置rsync，并赋值权限。
mkdir -p /etc/rsync
\cp -rf $rsync_path/config/* /etc/rsync
\cp -rf $rsync_path/config/rsyncd.conf /etc/
chmod -R 600 /etc/rsync
chmod -R 600 /etc/rsyncd.conf
chmod -R 777 /etc/rsync/*.sh

## 4：加载服务
\cp -rf $current_path/rsync.service  /usr/lib/systemd/system/rsync.service
systemctl daemon-reload


